<template>
    <div>
        <div ref="location" style="width: 100%;height: 1000px;"></div>
    </div>
</template>

<script>
    import echarts from 'echarts'
    import chinaJson from "echarts/map/json/china"

    export default {
        name: "location",
        data() {
            return {
                chart: null,
                data:[{"city":"安庆","count":491},{"city":"鞍山","count":1618},{"city":"巴南","count":97},{"city":"白山","count":1519},{"city":"蚌埠","count":1162},{"city":"包头","count":1866},{"city":"宝坻","count":139},{"city":"宝鸡","count":9202},{"city":"保定","count":888},{"city":"北辰","count":446},{"city":"北海","count":111},{"city":"滨州","count":12795},{"city":"沧州","count":177},{"city":"昌平","count":1385},{"city":"常德","count":771},{"city":"常州","count":7948},{"city":"朝阳","count":38789},{"city":"潮州","count":3165},{"city":"郴州","count":724},{"city":"成都","count":16937},{"city":"崇明","count":890},{"city":"崇文","count":896},{"city":"滁州","count":3732},{"city":"楚雄","count":647},{"city":"大港","count":4657},{"city":"大连","count":13986},{"city":"大庆","count":52},{"city":"大同","count":379},{"city":"大兴","count":6480},{"city":"大兴安岭","count":13632},{"city":"德阳","count":16318},{"city":"德州","count":2856},{"city":"东城","count":2122},{"city":"东莞","count":2508},{"city":"东营","count":4214},{"city":"鄂尔多斯","count":3573},{"city":"防城港","count":1348},{"city":"丰台","count":11934},{"city":"奉贤","count":2863},{"city":"佛山","count":10331},{"city":"福州","count":18989},{"city":"抚州","count":2683},{"city":"赣州","count":1083},{"city":"固原","count":3831},{"city":"广安","count":174},{"city":"广元","count":1924},{"city":"广州","count":64743},{"city":"贵港","count":980},{"city":"贵阳","count":375},{"city":"桂林","count":3591},{"city":"哈尔滨","count":31491},{"city":"海淀","count":9614},{"city":"海口","count":2857},{"city":"汉中","count":21467},{"city":"杭州","count":35588},{"city":"合肥","count":5907},{"city":"和平","count":152},{"city":"河池","count":583},{"city":"河东","count":10996},{"city":"河西","count":5046},{"city":"菏泽","count":174},{"city":"鹤壁","count":3815},{"city":"黑河","count":181},{"city":"衡水","count":1977},{"city":"衡阳","count":4351},{"city":"虹口","count":28280},{"city":"呼和浩特","count":14265},{"city":"呼伦贝尔","count":2},{"city":"湖州","count":2178},{"city":"淮安","count":2644},{"city":"淮北","count":5300},{"city":"黄石","count":14},{"city":"惠州","count":2027},{"city":"吉林","count":4239},{"city":"济南","count":40103},{"city":"济宁","count":1277},{"city":"嘉定","count":3840},{"city":"嘉兴","count":19206},{"city":"江门","count":583},{"city":"焦作","count":1404},{"city":"揭阳","count":999},{"city":"金华","count":7566},{"city":"金山","count":1546},{"city":"津南","count":5998},{"city":"晋中","count":1824},{"city":"荆州","count":11545},{"city":"静安","count":1053},{"city":"九龙坡","count":4535},{"city":"开封","count":5142},{"city":"昆明","count":1785},{"city":"莱芜","count":496},{"city":"兰州","count":2038},{"city":"廊坊","count":760},{"city":"连云港","count":449},{"city":"辽阳","count":96},{"city":"辽源","count":5412},{"city":"聊城","count":3778},{"city":"六盘水","count":4495},{"city":"龙岩","count":124},{"city":"卢湾","count":8},{"city":"洛阳","count":2380},{"city":"梅州","count":75},{"city":"密云","count":2771},{"city":"闵行","count":32213},{"city":"牡丹江","count":1535},{"city":"南昌","count":11570},{"city":"南充","count":7301},{"city":"南汇","count":1108},{"city":"南京","count":46523},{"city":"南开","count":11539},{"city":"南宁","count":1082},{"city":"南平","count":2208},{"city":"南通","count":22543},{"city":"南阳","count":2456},{"city":"宁波","count":8356},{"city":"盘锦","count":5334},{"city":"萍乡","count":3286},{"city":"莆田","count":80},{"city":"浦东","count":28639},{"city":"普陀","count":30175},{"city":"齐齐哈尔","count":1925},{"city":"青岛","count":15905},{"city":"青浦","count":8004},{"city":"清远","count":5766},{"city":"衢州","count":6941},{"city":"泉州","count":3520},{"city":"日照","count":9},{"city":"三门峡","count":969},{"city":"三明","count":319},{"city":"沙坪坝","count":2451},{"city":"厦门","count":7261},{"city":"汕头","count":12327},{"city":"商丘","count":716},{"city":"上饶","count":2548},{"city":"韶关","count":10520},{"city":"绍兴","count":7786},{"city":"深圳","count":9328},{"city":"沈阳","count":27704},{"city":"十堰","count":1327},{"city":"石河子","count":984},{"city":"石家庄","count":12759},{"city":"石景山","count":2637},{"city":"双鸭山","count":143},{"city":"顺义","count":1607},{"city":"四平","count":1485},{"city":"松江","count":3139},{"city":"苏州","count":21549},{"city":"随州","count":1008},{"city":"台州","count":3263},{"city":"太原","count":24956},{"city":"泰安","count":2360},{"city":"泰州","count":176},{"city":"唐山","count":13190},{"city":"塘沽","count":1314},{"city":"通化","count":26},{"city":"威海","count":69},{"city":"潍坊","count":1900},{"city":"温州","count":5421},{"city":"乌兰察布","count":2333},{"city":"乌鲁木齐","count":3317},{"city":"无锡","count":8594},{"city":"芜湖","count":1214},{"city":"梧州","count":1733},{"city":"武汉","count":16131},{"city":"武清","count":1356},{"city":"西安","count":16010},{"city":"西城","count":3944},{"city":"咸宁","count":363},{"city":"咸阳","count":9554},{"city":"襄樊","count":6540},{"city":"新乡","count":7004},{"city":"邢台","count":8411},{"city":"宿迁","count":4453},{"city":"徐汇","count":1976},{"city":"徐州","count":7069},{"city":"宣城","count":2017},{"city":"宣武","count":4390},{"city":"烟台","count":1460},{"city":"延安","count":1049},{"city":"盐城","count":5879},{"city":"扬州","count":8595},{"city":"阳江","count":9},{"city":"杨浦","count":6972},{"city":"伊春","count":1529},{"city":"宜宾","count":130},{"city":"鹰潭","count":149},{"city":"渝北","count":20},{"city":"玉溪","count":106},{"city":"岳阳","count":6618},{"city":"云浮","count":1562},{"city":"枣庄","count":1267},{"city":"闸北","count":2439},{"city":"湛江","count":12446},{"city":"张掖","count":2074},{"city":"漳州","count":82},{"city":"长春","count":30009},{"city":"长宁","count":6180},{"city":"长沙","count":8493},{"city":"肇庆","count":9198},{"city":"郑州","count":17292},{"city":"中山","count":5602},{"city":"珠海","count":15506},{"city":"驻马店","count":424},{"city":"淄博","count":2180},{"city":"自贡","count":924},{"city":"遵义","count":21}]
            }
        },
        mounted() {
            echarts.registerMap("china",chinaJson);
            this.chart = echarts.init(this.$refs.location);
            var geoCoordMap = {
                "海门": [121.15, 31.89],
                "鄂尔多斯": [109.781327, 39.608266],
                "招远": [120.38, 37.35],
                "舟山": [122.207216, 29.985295],
                "齐齐哈尔": [123.97, 47.33],
                "盐城": [120.13, 33.38],
                "赤峰": [118.87, 42.28],
                "青岛": [120.33, 36.07],
                "乳山": [121.52, 36.89],
                "金昌": [102.188043, 38.520089],
                "泉州": [118.58, 24.93],
                "莱西": [120.53, 36.86],
                "日照": [119.46, 35.42],
                "胶南": [119.97, 35.88],
                "南通": [121.05, 32.08],
                "拉萨": [91.11, 29.97],
                "云浮": [112.02, 22.93],
                "梅州": [116.1, 24.55],
                "文登": [122.05, 37.2],
                "上海": [121.48, 31.22],
                "攀枝花": [101.718637, 26.582347],
                "威海": [122.1, 37.5],
                "承德": [117.93, 40.97],
                "厦门": [118.1, 24.46],
                "汕尾": [115.375279, 22.786211],
                "潮州": [116.63, 23.68],
                "丹东": [124.37, 40.13],
                "太仓": [121.1, 31.45],
                "曲靖": [103.79, 25.51],
                "烟台": [121.39, 37.52],
                "福州": [119.3, 26.08],
                "瓦房店": [121.979603, 39.627114],
                "即墨": [120.45, 36.38],
                "抚顺": [123.97, 41.97],
                "玉溪": [102.52, 24.35],
                "张家口": [114.87, 40.82],
                "阳泉": [113.57, 37.85],
                "莱州": [119.942327, 37.177017],
                "湖州": [120.1, 30.86],
                "汕头": [116.69, 23.39],
                "昆山": [120.95, 31.39],
                "宁波": [121.56, 29.86],
                "湛江": [110.359377, 21.270708],
                "揭阳": [116.35, 23.55],
                "荣成": [122.41, 37.16],
                "连云港": [119.16, 34.59],
                "葫芦岛": [120.836932, 40.711052],
                "常熟": [120.74, 31.64],
                "东莞": [113.75, 23.04],
                "河源": [114.68, 23.73],
                "淮安": [119.15, 33.5],
                "泰州": [119.9, 32.49],
                "南宁": [108.33, 22.84],
                "营口": [122.18, 40.65],
                "惠州": [114.4, 23.09],
                "江阴": [120.26, 31.91],
                "蓬莱": [120.75, 37.8],
                "韶关": [113.62, 24.84],
                "嘉峪关": [98.289152, 39.77313],
                "广州": [113.23, 23.16],
                "延安": [109.47, 36.6],
                "太原": [112.53, 37.87],
                "清远": [113.01, 23.7],
                "中山": [113.38, 22.52],
                "昆明": [102.73, 25.04],
                "寿光": [118.73, 36.86],
                "盘锦": [122.070714, 41.119997],
                "长治": [113.08, 36.18],
                "深圳": [114.07, 22.62],
                "珠海": [113.52, 22.3],
                "宿迁": [118.3, 33.96],
                "咸阳": [108.72, 34.36],
                "铜川": [109.11, 35.09],
                "平度": [119.97, 36.77],
                "佛山": [113.11, 23.05],
                "海口": [110.35, 20.02],
                "江门": [113.06, 22.61],
                "章丘": [117.53, 36.72],
                "肇庆": [112.44, 23.05],
                "大连": [121.62, 38.92],
                "临汾": [111.5, 36.08],
                "吴江": [120.63, 31.16],
                "石嘴山": [106.39, 39.04],
                "沈阳": [123.38, 41.8],
                "苏州": [120.62, 31.32],
                "茂名": [110.88, 21.68],
                "嘉兴": [120.76, 30.77],
                "长春": [125.35, 43.88],
                "胶州": [120.03336, 36.264622],
                "银川": [106.27, 38.47],
                "张家港": [120.555821, 31.875428],
                "三门峡": [111.19, 34.76],
                "锦州": [121.15, 41.13],
                "南昌": [115.89, 28.68],
                "柳州": [109.4, 24.33],
                "三亚": [109.511909, 18.252847],
                "自贡": [104.778442, 29.33903],
                "吉林": [126.57, 43.87],
                "阳江": [111.95, 21.85],
                "泸州": [105.39, 28.91],
                "西宁": [101.74, 36.56],
                "宜宾": [104.56, 29.77],
                "呼和浩特": [111.65, 40.82],
                "成都": [104.06, 30.67],
                "大同": [113.3, 40.12],
                "镇江": [119.44, 32.2],
                "桂林": [110.28, 25.29],
                "张家界": [110.479191, 29.117096],
                "宜兴": [119.82, 31.36],
                "北海": [109.12, 21.49],
                "西安": [108.95, 34.27],
                "金坛": [119.56, 31.74],
                "东营": [118.49, 37.46],
                "牡丹江": [129.58, 44.6],
                "遵义": [106.9, 27.7],
                "绍兴": [120.58, 30.01],
                "扬州": [119.42, 32.39],
                "常州": [119.95, 31.79],
                "潍坊": [119.1, 36.62],
                "重庆": [106.54, 29.59],
                "台州": [121.420757, 28.656386],
                "南京": [118.78, 32.04],
                "滨州": [118.03, 37.36],
                "贵阳": [106.71, 26.57],
                "无锡": [120.29, 31.59],
                "本溪": [123.73, 41.3],
                "克拉玛依": [84.77, 45.59],
                "渭南": [109.5, 34.52],
                "马鞍山": [118.48, 31.56],
                "宝鸡": [107.15, 34.38],
                "焦作": [113.21, 35.24],
                "句容": [119.16, 31.95],
                "北京": [116.46, 39.92],
                "徐州": [117.2, 34.26],
                "衡水": [115.72, 37.72],
                "包头": [110, 40.58],
                "绵阳": [104.73, 31.48],
                "乌鲁木齐": [87.68, 43.77],
                "枣庄": [117.57, 34.86],
                "杭州": [120.19, 30.26],
                "淄博": [118.05, 36.78],
                "鞍山": [122.85, 41.12],
                "溧阳": [119.48, 31.43],
                "库尔勒": [86.06, 41.68],
                "安阳": [114.35, 36.1],
                "开封": [114.35, 34.79],
                "济南": [117, 36.65],
                "德阳": [104.37, 31.13],
                "温州": [120.65, 28.01],
                "九江": [115.97, 29.71],
                "邯郸": [114.47, 36.6],
                "临安": [119.72, 30.23],
                "兰州": [103.73, 36.03],
                "沧州": [116.83, 38.33],
                "临沂": [118.35, 35.05],
                "南充": [106.110698, 30.837793],
                "天津": [117.2, 39.13],
                "富阳": [119.95, 30.07],
                "泰安": [117.13, 36.18],
                "诸暨": [120.23, 29.71],
                "郑州": [113.65, 34.76],
                "哈尔滨": [126.63, 45.75],
                "聊城": [115.97, 36.45],
                "芜湖": [118.38, 31.33],
                "唐山": [118.02, 39.63],
                "平顶山": [113.29, 33.75],
                "邢台": [114.48, 37.05],
                "德州": [116.29, 37.45],
                "济宁": [116.59, 35.38],
                "荆州": [112.239741, 30.335165],
                "宜昌": [111.3, 30.7],
                "义乌": [120.06, 29.32],
                "丽水": [119.92, 28.45],
                "洛阳": [112.44, 34.7],
                "秦皇岛": [119.57, 39.95],
                "株洲": [113.16, 27.83],
                "石家庄": [114.48, 38.03],
                "莱芜": [117.67, 36.19],
                "常德": [111.69, 29.05],
                "保定": [115.48, 38.85],
                "湘潭": [112.91, 27.87],
                "金华": [119.64, 29.12],
                "岳阳": [113.09, 29.37],
                "长沙": [113, 28.21],
                "衢州": [118.88, 28.97],
                "廊坊": [116.7, 39.53],
                "菏泽": [115.480656, 35.23375],
                "合肥": [117.27, 31.86],
                "武汉": [114.31, 30.52],
                "大庆": [125.03, 46.58]
            };
            var convertGeoData=function (data) {
                var res = [];
                for (var i = 0; i < data.length; i++) {
                    var geoCoord = geoCoordMap[data[i].city];
                    if (geoCoord) {
                        let tem={
                            name: data[i].city,
                            value: geoCoord.concat(data[i].count)
                        };
                        res.push(tem);
                    }
                }
                return res;
            };
            let option = {
                title: {
                    text: '全国主要使用城市',
                    x: 'center',
                },
                tooltip: {
                    trigger: 'item',
                    formatter: function (params) {
                        return  `${params.data.name}:${params.data.value[2]}次`
                    }
                },
                legend: {
                    orient: 'vertical',
                    y: 'bottom',
                    x: 'right',
                    data: ['pm2.5'],
                    textStyle: {
                        color: '#fff'
                    }
                },
                visualMap: {
                    min: 0,
                    max: 200,
                    calculable: true,
                    inRange: {
                        color: ['#50a3ba', '#eac736', '#ff5f7f']
                    },
                    textStyle: {
                        color: '#00ffbb'
                    }
                },
                geo: {
                    map: 'china',
                    itemStyle: {
                        normal: {
                            areaColor: '#323c48',
                            borderColor: '#111'
                        },
                        emphasis: {
                            areaColor: '#2a333d'
                        }
                    }
                },
                series: [
                    {
                        name: 'pm2.5',
                        type: 'effectScatter',
                        coordinateSystem: 'geo',
                        data: convertGeoData(this.data),
                        symbolSize: function(val){
                           return val[2]*0.0009;
                        },
                        label: {
                            normal: {
                                show: false
                            },
                            emphasis: {
                                show: false
                            }
                        },
                        itemStyle: {
                            emphasis: {
                                borderColor: '#fff',
                                borderWidth: 1
                            }
                        }
                    }
                ]
            }
            this.chart.setOption(option)
        },
        computed: {}, methods: {}
    }
</script>

<style scoped>

</style>